//------------------------------------------------------------------------------
//  <copyright file="SharedBufferParams.h" company="Microsoft Corporation">
// The MIT License (MIT)
// 
// Copyright (c) 2014, Microsoft Corporation
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
//  </copyright>
//------------------------------------------------------------------------------	

#pragma once

#include "stdafx.h"
#include "RegisterExchange.h"
#include "KukaLBR4PlusControllerExports.h"
#include "ControllerStateMachineExports.h"
#include <ControllerStateMachineDescription.cs>
#include <Windows.h>

/// <summary> Contains parameters needed to initialize communication between IO and controller components. </summary>
struct KUKALBR4PLUSCONTROLLER_DLLEXPORTIMPORT SharedBufferParameters
{
	/// <summary>
	/// Object for exchanging working registers between upstream client message handler and controller loop.
	/// These registers serve as input from the client to the controller state machine.  </summary>
	/// </summary>
	RegisterExchange<double> *pWorkingRegistersExchange;

	/// <summary>
	/// Object for exchanging all registers (both working and feedback) between upstream client message handler
	/// and controller loop.  These registers serve as feedback from the HW and controller state machine to the
	/// client.
	/// </summary>
	RegisterExchange<double> *pAllRegistersExchange;

	/// <summary> Exchange buffer for controller state machine description. </summary>
	RegisterExchange<byte>  *pCsmdExchange;

	/// <summary> Signals that one thread has indicated it is quitting. </summary>
	unsigned volatile int* pQuitSignal;

	/// <summary> Buffer used for exchanging controller state machine current status. </summary>
	unsigned volatile int* pCsmdStatusSignal;

	/// <summary>
	/// Buffer used for indicating that controller state machine and working registers are ready for consumption
	/// 0 - not ready (buffers should not current be consumed by controller thread)
	/// 1 - ready (consistent state machine and registers present in exchange buffers)
	/// 2 - consuming (controller thread is in process of consuming new state machine and registers, so message handler thread should not change them until status changes back to "not ready")
	/// </summary>
	unsigned volatile int* pNewCsmdReadySignal;

	/// <summary>
	/// Creates a new instance of the <c>SharedBufferParameters</c> class.
	/// Utilizies the register definitions KukaLBR4Definitions.h for register configuration.
	/// </summary>
	SharedBufferParameters();

	/// <summary> dtor. </summary>
	~SharedBufferParameters();
};
